<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注册</title>
		<link rel="stylesheet"
		    href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
		    integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
		    crossorigin="anonymous">
	</head>
	<body>
		<h2>实验三第(2)问：加入格式实现功能点击下面链接跳转到上一问</h2>
		<a href="index.html">（点这里）实验三第(1)问</a>
		<br><hr>
			<div class="container">
				<div class="row" style="margin-top: 30px">
					<div class="col-md-4 col-md-offset-4">
						<div class="panel panel-primary">
							<div class="panel-heading">
								<span class="glyphicon glyphicon-user"></span>注册
							</div>
							<div class="panel-body">
								<form name="registerForm">
									<div class="form-group">
										<label for="name">用户名</label> 
										<input type="text"class="form-control" name="name" placeholder="请输入用户名">
									</div>
									<div class="form-group">
										<label for="">密码</label> 
										<input type="password" class="form-control" name="pwd" placeholder="请输入密码">
									</div>
									<div class="form-group">
										<label for="">确认密码</label> 
										<input type="password"class="form-control" name="repwd" placeholder="请再次输入密码">
									</div>
									<div class="form-group">
										<label for="">年龄</label>
										<input type="number" class="form-control" name="age" placeholder="请输入年龄"/>
									</div>
									
									<div>
										<label for="">体重</label>
										<input type="number" class="form-control" name="weight" placeholder="请输入体重(公斤)"/>
									</div>
									<div>
										<label for="">邮箱</label>
										<input type="email" class="form-control" name="email" placeholder="请输入邮箱" />
									</div>
									<br>
									<button type="submit" class="btn btn-primary"
										onclick="return checkForm()">注册</button>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
			
			 <script
			        src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"
			        integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
			        crossorigin="anonymous"></script>
			<script type="text/javascript">
			        function checkForm() {
			            var name = registerForm.name.value;
			            var pwd = registerForm.pwd.value;
			            var repwd = registerForm.repwd.value;
						var age = registerForm.age.value;
						var weight = registerForm.weight.value;
						var email = registerForm.email.value
			            //alert(name + pwd + repwd);
			            if (name == "" || name == null) {
			                alert("注册失败！用户名不能为空");
			                registerForm.name.focus();
			                return false;
			            } else if (pwd == "" || pwd == null) {
			                alert("注册失败！密码不能为空");
			                registerForm.pwd.focus();
			                return false;
			            } else if (repwd == "" || repwd == null) {
			                alert("注册失败！重复密码不能为空");
			                registerForm.repwd.focus();
			                return false;
			            }else if(pwd!=repwd){
			                alert("注册失败！两次密码输入不一致，请重新输入!");
			                registerForm.repwd.focus();
			                return false;
			            }else if(pwd.length<8){
							alert("注册失败！密码长度不能小于8位");
							registerForm.pwd.focus();
							return false;
						}else if(age<17){
							alert("注册失败！年龄小于17岁不能注册哦！");
							registerForm.age.focus();
							return false;
						}else if(weight<30 || weight>150){
							alert("注册失败！您的体重有问题哦！");
							registerForm.weight.focus();
							return false;
						}
			            alert('注册成功！');
			            return true;
			        }
			    </script>
	</body>
</html>
